Skip to content

fix: accept numpy integer types as Parachute trigger - #1116

Open
abhi-0203 wants to merge 1 commit into
RocketPy-Team:developfrom
abhi-0203:fix/numpy-integer-trigger
Open

fix: accept numpy integer types as Parachute trigger#1116
abhi-0203 wants to merge 1 commit into
RocketPy-Team:developfrom
abhi-0203:fix/numpy-integer-trigger

Conversation

@abhi-0203

Copy link
Copy Markdown

Summary

Replace isinstance(trigger, (int, float)) with isinstance(trigger, Real) and not isinstance(trigger, bool) in Parachute.__init__().

numpy.int64 and numpy.int32 don't subclass Python's int or float, so they were rejected with a ValueError even though they represent valid numeric altitude values. numbers.Real covers all numeric types (int, float, numpy scalars).

Also excludes bool — currently trigger=True is silently accepted as a 1m height, which is never intentional.

Changes

  • rocketpy/rocket/parachute.py: Import Real from numbers, replace isinstance(trigger, (int, float)) with isinstance(trigger, Real) and not isinstance(trigger, bool)

Test plan

  • int 800 → accepted ✓
  • float 800.0 → accepted ✓
  • np.float64(800) → accepted ✓
  • np.int64(800) → accepted ✓
  • np.int32(800) → accepted ✓
  • True / False → rejected ✓ (was previously accepted as height 1m)

AST verified: no old pattern remains, import confirmed.

Closes #1106

@abhi-0203
abhi-0203 requested a review from a team as a code owner August 9, 2026 04:32

@Gui-FernandesBR Gui-FernandesBR left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest using "NUMERICAL_TYPES" constant from the Function module

@ting-hong-shieh

Copy link
Copy Markdown

I exercised the trigger-type boundary on head e3d2f0fe7c583f3a632d9643dca98b071c60b79f:

Trigger type Result
Python int, NumPy int64 accepted
Python float, NumPy float32 accepted
Python bool, NumPy bool_ rejected with ValueError
Python complex, NumPy complex64 rejected with ValueError

Using numbers.Real with the explicit bool guard gives the intended boundary. A raw NUMERICAL_TYPES check would also include complex values, and Python bool needs its own exclusion, so I would keep the current predicate even though the shared constant was suggested earlier.

Two changes still look necessary before review:

  1. The pull request targets master; the development guide says ordinary fixes should target develop.
  2. The patch has no tests. A parametrized constructor test covering the eight cases above would protect both the NumPy-integer fix and the bool/complex exclusions.

No branch changes were made. Environment: Python 3.12.6; NumPy 2.5.2; RocketPy PR head above; macOS 26.5.2 arm64.

@Gui-FernandesBR
Gui-FernandesBR changed the base branch from master to develop August 14, 2026 09:45
@Gui-FernandesBR

Copy link
Copy Markdown
Member

I understand this PR still needs some fixes.

  1. Adding unit tests
  2. Using the NUMERICAL_TYPES from the Function module

@codecov

codecov Bot commented Aug 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.37%. Comparing base (e0ff281) to head (e3d2f0f).
⚠️ Report is 58 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1116      +/-   ##
===========================================
+ Coverage    82.18%   82.37%   +0.19%     
===========================================
  Files          122      122              
  Lines        16355    16378      +23     
===========================================
+ Hits         13441    13492      +51     
+ Misses        2914     2886      -28     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

isinstance(trigger, (int, float)) rejects numpy integer types
(np.int64, np.int32) because they don't subclass Python's int or float.
Replace with isinstance(trigger, numbers.Real) which covers all numeric
types (int, float, numpy scalars) while excluding bool.

Fixes RocketPy-Team#1106
@Gui-FernandesBR
Gui-FernandesBR force-pushed the fix/numpy-integer-trigger branch from e3d2f0f to 7bb58b7 Compare August 15, 2026 12:24
@Gui-FernandesBR

Copy link
Copy Markdown
Member

Thanks for the boundary table — that settles the NUMERICAL_TYPES question, and you are right to keep your predicate. I checked the constant:

NUMERICAL_TYPES = (float, int, complex, np.integer, np.floating, np.complexfloating)

so it would accept complex / np.complex64, and because bool subclasses int it would not reject True either. numbers.Real plus the explicit bool guard is the correct boundary here. Dropping that request — please ignore item 2 of my earlier comment.

What is still missing is item 1, the tests. The diff is still only the one-line predicate change in parachute.py. Please add unit tests (tests/unit/rocket/test_parachute.py or tests/unit/test_parachute_triggers.py) that pin exactly the table you posted:

  • int and np.int64 accepted as an altitude trigger
  • float and np.float32 accepted
  • bool and np.bool_ rejected with ValueError
  • complex and np.complex64 rejected with ValueError

That way the boundary you measured by hand is the boundary CI enforces from now on. With those in, this is good to go.

One note: the workflow runs on this PR had been sitting in action_required and never actually executed, so the green/absent checks were not meaningful. I approved them, so you should get real results now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parachute refuses a numpy integer trigger but accepts a numpy float

3 participants